﻿using System.Data.SQLite;

namespace RobosimAPI.Class
{
	public class EventMap
	{
		/*
		CREATE TABLE event_map (
		id           INTEGER,
		file_encrypt INTEGER,
		map_md5      TEXT,
		map_password TEXT,
		map_url      TEXT
		);
		*/
		public int Id;
		public int FileEncrypt;
		public string? MapMd5;
		public string? MapPassword;
		public string? MapUrl;
		public EventMap(int map_id)
		{
			using (var conn = new SQLiteConnection(Account.DB_CONNECTION_STRING))
			{
				conn.Open();
				using (var cmd = new SQLiteCommand(conn))
				{
					cmd.CommandText = "SELECT * FROM event_map WHERE id = @id";
					cmd.Parameters.AddWithValue("@id", map_id);
					using (var reader = cmd.ExecuteReader())
					{
						while (reader.Read())
						{
							Id = reader.GetInt32(0);
							FileEncrypt = reader.GetInt32(1);
							MapMd5 = reader.GetString(2);
							MapPassword = reader.GetString(3);
							MapUrl = reader.GetString(4);
						}
					}
				}
				conn.Close();
				conn.Dispose();
			}
		}
	}
}
